package com.example.utils;

import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class LengthValidator implements View.OnFocusChangeListener {

    private final Context context;
    private final int length;
    private final String tips;

    public LengthValidator(Context context,int length,String tips){
        this.context = context;
        this.length = length;
        this.tips = tips;
    }


    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        EditText editText = (EditText) v;

        if(hasFocus){
            return;
        }
        String text = editText.getText().toString();
        if (text.length()!=11) {
            Toast.makeText(context,tips,Toast.LENGTH_SHORT).show();
        }
    }
}
